﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebShopData;

namespace WebShop_Project
{
    public partial class MasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Response.Redirect("http://localhost:26945/Login.aspx");
            }
            if (Session["ShoppingCart"] != null)
            {
                DropDownList1.Items.Clear();
                ListItem listItem = new ListItem("Visa Kundvagn");
                DropDownList1.Items.Add(listItem);
                List<ShoppingCartItem> shoppingCartItems = (List<ShoppingCartItem>)Session["ShoppingCart"];
                foreach (var shoppingCartItem in shoppingCartItems)
                {
                    listItem = new ListItem(string.Format("{0} st {1}", shoppingCartItem.Quantity, shoppingCartItem.Article.ArticleName));
                    DropDownList1.Items.Add(listItem);
                }
            }
            else
            {
                List<ShoppingCartItem> shoppingCartItems = new List<ShoppingCartItem>();
                Session.Add("ShoppingCart", shoppingCartItems);
            }
        }
    }
}